package com.c2.web.front;

import com.c2.entity.EbUser;
import com.c2.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("login")
public class LoginController {
    @Autowired
    private UserService userService;

    @RequestMapping("to_login")
    public String toLogin() {
        return "login";
    }


    @RequestMapping("/login")
    public String login(HttpServletRequest request, String euUserId, String euPassword) {
        EbUser lgnUser = userService.Login(euUserId, euPassword);
        HttpSession session = request.getSession();
        if (lgnUser == null) {
            session.setAttribute("lgn_error", "lgn_error");
            return "login";
        }
        session.setAttribute("lgnUser",lgnUser);
        session.removeAttribute("lgn_error");
        return "index";

    }
}

